#
#  Makefile for Horizon - kernel
#
#  Francesco Frigo
#  Tuesday 17th September, 2002
#
#  Updated on: Sunday 28th December, 2003
#

INCLUDEDIR = -I./include -I./lib/include
CFLAGS = -nostdinc -nostdlib -nostartfiles -fno-builtin -fwritable-strings -Wall -W -g
MANAGERSDIR = ./managers
LIBDIR = ./lib
KICKSTARTDIR = ./kickstart

CC=gcc-3.3

LIBS = -lk -lll
ENTRY = start
RELOC = 0x80000000
OUTF = system.bin
DBG_OUTF = system-dbg.o

MANAGERSOBJS =  \
		$(MANAGERSDIR)/vmm/*.o \
		$(MANAGERSDIR)/kbd/*.o \
		$(MANAGERSDIR)/tty/*.o \
		$(MANAGERSDIR)/hdd/*.o \
		$(MANAGERSDIR)/bus/*.o

OBJS = $(KICKSTARTDIR)/*.o ./*.o $(MANAGERSOBJS) $(LIBDIR)/libk.a $(LIBDIR)/libll.a

all: $(OUTF)

debug: $(OUTF)
	ld -T linker-dbg.ld -Ttext $(RELOC) --entry $(ENTRY) -L$(LIBDIR) -o $(DBG_OUTF) $(OBJS) --warn-common


$(OUTF):
	$(CC) -c $(CFLAGS) $(INCLUDEDIR) *.c
	as -o i386_arch.o i386_arch.s
	as -o interrupts.o interrupts.s
	as -o spinlock.o spinlock.s
	make -C $(MANAGERSDIR)/vmm
	make -C $(MANAGERSDIR)/kbd
	make -C $(MANAGERSDIR)/tty
	make -C $(MANAGERSDIR)/hdd
	make -C $(MANAGERSDIR)/bus
	make -C kickstart
	make -C lib
	ld -T linker.ld -Ttext $(RELOC) --entry $(ENTRY) -L$(LIBDIR) -o $(OUTF) $(OBJS) --warn-common

clean: objremove
	make -C kickstart clean
	make -C lib clean
	make -C $(MANAGERSDIR)/vmm clean
	make -C $(MANAGERSDIR)/kbd clean
	make -C $(MANAGERSDIR)/tty clean
	make -C $(MANAGERSDIR)/hdd clean
	make -C $(MANAGERSDIR)/bus clean
	rm -f *~ $(OUTF)

objremove:
	rm -f *.o

depend:
	makedepend $(INCLUDEDIR) *.c
